<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
	<script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
	    function change_html(){
	        var font_size=$(window).width()/16;
	        $("html").css('font-size',font_size);
	    }
	    window.onresize=function(){
	        change_html();
	    }
	    change_html();
	</script>
	<title>找回密码</title>
	<style type="text/css">
		*{margin: 0;padding: 0;text-decoration: none;}
		body{background: #eeeeee;}
		.tc{text-align: center;}
		.fl{float: left;}
		.fr{float: right;}
		.title{width: 16rem;height: 2rem;font-size: 0.68rem;color: #2d2f2c;line-height: 2rem;background: white;}
		.back{width: 2rem;height: 2rem;background: url(images/back_btn.png) 0 no-repeat;background-size: 100% auto;position: fixed;top: 0;}
		.bar{height: 2.383rem;line-height: 2.383rem;background: white;}
		.l_word{width: 2.893rem;padding-left: 0.851rem;font-size: 0.68rem;}
		.gray_line{width: 15rem;height: 1px;background: #eeeeee;margin:0 auto;}
		input{vertical-align: middle;border: none;outline: none;}
		.login{height: 1.91rem;width: 15rem;margin: 0 auto;display: block;margin-top: 0.5rem;border-radius: 0.2rem;color: white;background: red;font-size: 0.68rem;margin-bottom: 0.5rem;}
		.red{font-size: 0.55rem;color: #808d9d;padding-right: 0.5rem;}
		.mobile_code{padding: 0.3rem;background: white;border-radius: 0.6rem;border: 1px solid red;color: red;}
	</style>
</head>
<body>
	<div class="title tc">找回密码
		<div class="back" onclick="history.go(-1);"></div>
	</div>
	<form method="post" action="" id="myform" onsubmit="return login_check()">
		<input type="hidden" name="siteid" value="{$siteid}" />
		<div class="bar">
			<div class="bar fl l_word">手机号</div>
			<input type="text" name="username" id="username" placeholder="请输入手机号" onblur="check_username()">
		</div>
		<div class="gray_line"></div>
		<div class="bar">
			<div class="bar fl l_word">新密码</div>
			<input type="password" name="password" id="password" placeholder="请输入密码">
		</div>
		<div class="gray_line"></div>
		<div class="bar">
			<div class="bar fl l_word">重复密码</div>
			<input type="password" name="cfm_password" id="cfm_password" placeholder="请输入密码">
		</div>
		<div class="gray_line"></div>
		<div class="bar">
			<div class="bar fl l_word">验证码</div>
			<input type="text" name="check_code" id="check_code" placeholder="请输入验证码" style="width: 4rem;">
			<input type="button" class="mobile_code" name="mobile_code" id="mobile_code" value="发送短信验证码" onclick="send_mobile_code()">
		</div>
		<div class="gray_line" style="width: 16rem;"></div>
		<input type="submit" name="dosubmit" id="dosubmit" value="提交" class="login">
	</form>
	<a href="{APP_PATH}index.php?m=member&c=index&a=register&siteid={$siteid}" class="red fr">注册</a>
	<a href="{APP_PATH}index.php?m=member&c=index&a=login&siteid={$siteid}" class="red fr">登录</a>
	<input type="hidden" name="yj_url" id="yj_url" value="{APP_PATH}index.php?m=member&c=index&a=public_check_name&siteid={$siteid}">

</body>
<script type="text/javascript">
	var time = 5;
	var interval = time;
	var yj_clock;

	function send_mobile_code(){
		var mobile = $('#username').val();
		var partten = /^1[3-9]\d{9}$/;
		if(!partten.test(mobile)){
			alert("请输入正确的手机号码");
			return false;
		}
		$("#mobile_code").attr('disabled',true);
		yj_clock = window.setInterval("clock()",1000);
		$.ajax({
		    url: "sendSms.php",
		    type: 'POST',
		    dataType: 'text',
		    data: {
		        'mobile' : mobile,
				'type' : '1' 
		    },
		    success: function(res){
		    	console.log(res);
		         if (res == 1) {
		         	alert('发送成功！');
		         	return ;
		         }
		        alert('发送失败！');
		    },
		    error: function(){
		        alert('通信失败!');
		    }
		});
	}

	function clock()
	{
		if (interval > 0) {
			interval --;
			$("#mobile_code").val(interval+'秒后可重新发送');
		}else{
			clearInterval(yj_clock);
			interval = time;
			$("#mobile_code").attr('disabled',false);
			$("#mobile_code").val("发送短信验证码");
		}
	}

	function check_username(){
		var yj_url = $('#yj_url').val();
		var username = $('#username').val();
		$.ajax({
		    url: yj_url,
		    type: 'POST',
		    dataType: 'text',
		    data: {
		        'username' : username
		    },
		    success: function(res){
		    	if (res != -1) {
		    		alert('用户名不存在');
		    		$('#username').val('');
		    	}
		    },
		    error: function(){
		        alert('通信失败!');
		    }
		});
	}

	function login_check(){
		var username = $('#username').val();
		var password = $('#password').val();
		var mobile_code = $('#check_code').val();
		var cfm_password = $('#cfm_password').val();
		var err_msg = '';
		var patt = /^1[0-9]{10}$/;
		var pat_pwd = /\w{6,12}$/;
		
		if(!patt.test(username)){
			err_msg += '手机号码格式不正确\n';
		}
	
		if (!pat_pwd.test(password)) {
			err_msg += '密码格式为6-12位字符\n';
		}
		if (mobile_code == '') {
			err_msg += '验证码不能为空\n';
		}

		if (cfm_password != password) {
			err_msg += '两次密码输入不一致\n';
		}

		if (err_msg != '') {
			alert(err_msg);
			return false;
		}
		return true;
	}

</script>
</html>